$(function () {
	
	
    $("#jqGrid").jqGrid({
        url: baseURL + 'oa/oaplanconfig/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '标题', name: 'title', index: 'title', width: 80 }, 			
			{ label: '人员列表', name: 'planName', index: 'plan_name', width: 80 }, 			
			{ label: '计划日期', name: 'planDate', index: 'plan_date', width: 80 }, 
			{ label: '值班人数', name: 'count', index: 'plan_date', width: 80 },
			{ label: '值班天数', name: 'days', index: 'plan_date', width: 80 },
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
    
    console.log('加载完成');
    /*layui.use('laydate', function(){
	  var laydate = layui.laydate;
	  
	  //执行一个laydate实例
	  laydate.render({
	    elem: '#beginTime' //指定元素
	  });
	});*/
    
    
    $.get(baseURL + "oa/oaplanconfig/info", function(r){
    	
        console.log(r.oaPlanConfig);
        
    	var vm = new Vue({
    		el:'#rrapp',
    		data:{
    			showList: false,
    			title: null,
    			oaPlanConfig: r.oaPlanConfig
    		},
    		methods: {
    			query: function () {
    				vm.reload();
    			},
    			add: function(){
    				vm.showList = false;
    				vm.title = "新增";
    				vm.oaPlanConfig = {};
    			},
    			update: function (event) {
    				var id = getSelectedRow();
    				if(id == null){
    					return ;
    				}
    				vm.showList = false;
    	            vm.title = "修改";
    	            
    	            vm.getInfo(id)
    			},
    			saveOrUpdate: function (event) {
    				
    				console.log($('#beginTime').val());
    			
    				vm.oaPlanConfig.planDate = $('#beginTime').val();
    				var url = vm.oaPlanConfig.id == null ? "oa/oaplanconfig/save" : "oa/oaplanconfig/update";
    				$.ajax({
    					type: "POST",
    				    url: baseURL + url,
    	                contentType: "application/json",
    				    data: JSON.stringify(vm.oaPlanConfig),
    				    success: function(r){
    				    	if(r.code === 0){
    							alert('操作成功', function(index){
    								vm.reload();
    							});
    						}else{
    							alert(r.msg);
    						}
    					}
    				});
    			},
    			del: function (event) {
    				var ids = getSelectedRows();
    				if(ids == null){
    					return ;
    				}
    				
    				confirm('确定要删除选中的记录？', function(){
    					$.ajax({
    						type: "POST",
    					    url: baseURL + "oa/oaplanconfig/delete",
    	                    contentType: "application/json",
    					    data: JSON.stringify(ids),
    					    success: function(r){
    							if(r.code == 0){
    								alert('操作成功', function(index){
    									$("#jqGrid").trigger("reloadGrid");
    								});
    							}else{
    								alert(r.msg);
    							}
    						}
    					});
    				});
    			},
    			getInfo: function(id){
    				$.get(baseURL + "oa/oaplanconfig/info/"+id, function(r){
    	                vm.oaPlanConfig = r.oaPlanConfig;
    	            });
    			},
    			reload: function (event) {
    				vm.showList = false;
    				var page = $("#jqGrid").jqGrid('getGridParam','page');
    				$("#jqGrid").jqGrid('setGridParam',{ 
    	                page:page
    	            }).trigger("reloadGrid");
    			}
    		},
    		created: function () {
    			this.showList = false;
    			this.title = "修改";
    			console.log("初始化");
    		},
    		mounted: function() {
    			var _this = this;
    			//执行一个laydate实例
    		    /*laydate.render({
    		      elem: '#beginTime' //指定元素
    		    });*/
    			/*parent.layer.confirm("测试", {btn: ['确定','取消']},
    			function(){//确定事件
    				if(typeof(callback) === "function"){
    					callback("ok");
    				}
    			});*/
    			//执行一个laydate实例
    			laydate.render({
		             elem : '#beginTime' 
		             ,min: 0
		             ,max: 10000
		        });
    	
    			
    			/*aydate.render({
				  elem: '#test-limit2'
				  ,min: -7
				  ,max: 7
				});*/
    		
    			$('#beginTime').val(this.oaPlanConfig.planDate)
    			
    		},
    		
    	});
    });
    
    
    
    
});



